# -*- coding:utf-8 -*-
# @FileName :player_base.py
# @Created  :2024/9/29
# @Author   :天空之城
class Player:
    def __init__(self, id, name, chips):
        """
        初始化玩家对象

        :param name: 玩家姓名
        :param chips: 玩家初始的筹码数量
        """
        self.id = id
        self.name = name
        self.chips = chips  # 手上的筹码
        self.hole_cards = []  # 手牌
        self.current_bet = 0
        self.is_folded = False
        self.is_all_in = False
        self.has_acted = False  # 是否行动
        self.is_small_blind = False  # 是否为小盲
        self.is_big_blind = False  # 是否为大盲

    def bet(self, amount):
        """
        玩家下注

        :param amount: 下注金额
        """
        if amount > self.chips:
            raise ValueError(f"{self.name} 没有足够的筹码来下注 {amount}")
        self.chips -= amount
        self.current_bet += amount
        self.has_acted = True  # 玩家进行了下注操作

    def call(self, amount):
        """
        玩家跟注

        :param amount: 跟注金额
        """
        print('跟注金额', amount)
        call_amount = amount - self.current_bet if self.current_bet > 0 else 0
        if call_amount > self.chips:
            raise ValueError(f"{self.name} 没有足够的筹码来跟注 {call_amount}")
        self.bet(call_amount)
        self.has_acted = True  # 玩家进行了跟注操作
        print(f'{self.name}玩家进行了跟注操作,跟注{call_amount}\n')

    def raise_bet(self, amount):
        """
        玩家加注

        :param amount: 加注金额
        """
        self.bet(amount)
        self.has_acted = True  # 玩家进行了加注操作

    def all_in(self):
        """
        玩家全押
        """
        self.bet(self.chips)
        self.is_all_in = True
        self.has_acted = True  # 玩家进行了全押操作

    def fold(self):
        """
        玩家弃牌
        """
        self.is_folded = True
        self.has_acted = True  # 玩家进行了弃牌操作

    def reset_for_new_round(self):
        """
        每轮结束后重置玩家状态
        """
        self.hole_cards = []
        self.current_bet = 0
        self.is_folded = False
        self.is_all_in = False
        self.has_acted = False  # 重置玩家的行动状态

    def receive_cards(self, cards):
        """
        接收发给玩家的手牌

        :param cards: 一组手牌
        """
        self.hole_cards = cards

    def __str__(self):
        return f"Player(name={self.name}, chips={self.chips}, current_bet={self.current_bet}, is_folded={self.is_folded}, is_all_in={self.is_all_in})"
